package com.alone.mybatisplus.demo.handler;

import cn.hutool.core.lang.Pair;
import com.alone.mybatisplus.datascope.core.loader.DataScopeHandler;
import com.alone.mybatisplus.datascope.conts.DataScopeModel;
import com.alone.mybatisplus.datascope.conts.DataScopeType;
import org.springframework.stereotype.Component;

import java.util.*;

/**
 * @author Alone
 * @date 2022/5/13 3:03 下午
 */
@Component
public class DeptHandler extends DataScopeHandler {

    @Override
    public boolean canHandle(DataScopeModel model) {
        return DataScopeModel.DEPT == model;
    }

    @Override
    public boolean allowAll(Long userId, DataScopeModel model) {
        return false;
    }

    @Override
    protected void setInValue(Long userId, DataScopeModel model, List<Pair<String, Set<?>>> inValue) {
        Integer dataScopeType = 22;
        if (DataScopeType.DEPT_OWN_CHILD_LEVEL.getValue().equals(dataScopeType)) {
            inValue.add(Pair.of("id", Collections.singleton(1L)));
        } else if (DataScopeType.DEPT_OWN_LEVEL.getValue().equals(dataScopeType)) {
            inValue.add(Pair.of("id", Collections.singleton(1L)));
        }
    }

}
